package com.lx.base.exception;

import org.slf4j.Logger;

import java.util.Objects;


public class Exceptions {

    public static void checkCondition(boolean condition, CodeMessage codeMessage, String extMsg, Logger logger) {
        if (!condition) {
            if (Objects.nonNull(logger)) {
                logger.error(codeMessage.getMsg());
            }
            throw new BizException(codeMessage, extMsg);
        }

        return;
    }

    public static void checkCondition(boolean condition, CodeMessage codeMessage, String extMsg) {
        checkCondition(condition, codeMessage, extMsg, null);
    }

    public static void checkCondition(boolean condition, String extMsg) {
        checkCondition(condition, CommonError.INVALID_ARG, extMsg, null);
    }

    public static void checkIsNotNull(Object obj, String extMsg) {
        if (Objects.isNull(obj)) {
            checkCondition(false, CommonError.INVALID_ARG, extMsg, null);
        }
    }
}
